package com.lesson1;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import org.springframework.stereotype.Component;

/**
 * @author liliang
 * @date 2019/10/25.
 */
@Component
public class WsServer {

    private static final EventLoopGroup BOSS_GROUP;

    private static final EventLoopGroup CHILD_GROUP;

    private static final ServerBootstrap SERVER;

    public static final WsServer INSTANCE;

    private WsServer() {

    }

    static {
        INSTANCE = new WsServer();
        BOSS_GROUP = new NioEventLoopGroup();
        CHILD_GROUP = new NioEventLoopGroup();
        SERVER = new ServerBootstrap();
        SERVER.group(BOSS_GROUP, CHILD_GROUP)
                .channel(NioServerSocketChannel.class)
                .childHandler(new WsServerInitializer());
    }

    void start() {
        SERVER.bind(8088);
        System.out.println("netty webSocket server 启动完毕..");
    }



}
